home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 1187 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  3.6 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: stricmp()
  5. Date: Fri, 12 Jan 96 00:32:34 GMT
  6. Organization: none
  7. Message-ID: <821406754snz@genesis.demon.co.uk>
  8. References: <TANMOY.96Jan10212912@qcd.lanl.gov> <8213825629501@demosys.gcomm.com>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <8213825629501@demosys.gcomm.com>
  15.            jackal@gcomm.com "Jack Alvrus" writes:
  16.  
  17. >
  18. >TA>A rare post with so many wrong assumptions!!! :-)
  19. >
  20. >Well, if they're wrong it's a good thing I made this post to find out,
  21. >eh?  :)
  22. >
  23. >TA>   stricmp() is an ANSI library function, right?  So it should exhibit, if
  24. >
  25. >TA>no.
  26. >
  27. >So far that's been the overwhelming response, and if that is in fact
  28. >correct that's fine.
  29.  
  30. It is correct. ISO 9899-1990 (which is the standard re-adopted by ANSI) does
  31. not define a stricmp function.
  32.  
  33. > I do not have access to a copy of the ANSI C spec
  34. >so I cannot verify this for myself, however, the Borland C++ v4.5
  35. >Library Reference manual states that stricmp() is "defined by the ANSI C
  36. >standard."  Perhaps someone should notify Borland?
  37.  
  38. Probably.
  39.  
  40. >TA>   not consistent, at least *documented* behavior, right?
  41. >
  42. >TA>no and no. Usually library functions have certain requirments on their
  43. >TA>parameters, and a violation of these can lead to undefined behaviour,
  44. >TA>which need neither be consistent nor documented.
  45. >
  46. >Ah, but the requirements ARE documented.  If, under certain conditions,
  47. >behavior is undefined, then if those conditions are documented the
  48. >behavior is also documented.  These conditions are part of what I'm
  49. >trying to find out.
  50.  
  51. Any implementation can define behaviour for code that the C standard leaves
  52. undefined. Such code has defined behaviour but only under that particular
  53. implementation - i.e. it is not portable. The C language doesn't define
  54. any behaviour for stricmp() so you're entirely in the hands of the
  55. implementation. However consider:
  56.  
  57. strcmp("^", "a")
  58.  
  59. or even just
  60.  
  61. '^' > 'a'
  62.  
  63. strcmp is a standard C library function but even with this here you cannot
  64. tell from the C standard alone what the result of this will be (I guess
  65. you can determine that the characters/strings compare unequal). The C
  66. standard leaves the collating sequence of the character set implementation
  67. defined (except when the digits '0' to '9' are compared with each other).
  68. This means that the expressions above have values with will be consistent
  69. with other comparisons in the character set but you cannot tell in isolation
  70. what the result will be without reference to the implementation documentation.
  71. If you change to a different implementation you may get completely different
  72. results but they will be consistent within that implementation.
  73.  
  74. You could implement a function that takes 2 strings, transforms every
  75. character in both strings using the ANSI defined toupper() function and then
  76. compares the 2 resulting strings. This would be a reasonable definition of a
  77. stricmp function using only ANSI functions and operations (or you could
  78. use tolower all through instead of toupper). In that case you still can't
  79. determine purely from the C language standard whether "^" or "a" will
  80. compare greater. A conforming implementation must provide adequate
  81. documentation to determine this however. Of course this doesn't help define
  82. the stricmp function your implementation happens to provide at all.
  83.  
  84. -- 
  85. -----------------------------------------
  86. Lawrence Kirby | fred@genesis.demon.co.uk
  87. Wilts, England | 70734.126@compuserve.com
  88. -----------------------------------------
  89.